class Solution(object):
    def handleQuery(self, nums1, nums2, queries):
        n = len(nums1)
        max_range = n - 1
        p_1 = [0] * 4 * n
        rank = [0] * 4 * n
        self.sum = sum(nums2)
        def q1(node, l_s, r_s, l, r, v):
            if l <= l_s and r >= r_s:
                rank[node] = (rank[node] + 1) % 2
                p_1[node] = r_s - l_s + 1 - p_1[node]
            else:
                mid = (l_s + r_s) // 2
                if rank[node]:
                    rank[node] = 0
                    rank[2 * node + 1] = (rank[2 * node + 1] + 1) % 2
                    rank[2 * node + 2] = (rank[2 * node + 2] + 1) % 2
                    p_1[2 * node + 1] = mid - l_s + 1 - p_1[2 * node + 1]
                    p_1[2 * node + 2] = r_s - mid - p_1[2 * node + 2]
                if mid >= l:
                    q1(2 * node + 1, l_s, mid, l, r, 1)
                if mid + 1 <= r:
                    q1(2 * node + 2, mid + 1, r_s, l, r, 1)

                p_1[node] = p_1[2 * node + 1] + p_1[2 * node + 2]
        ans = []
        for i in range(n):
            if nums1[i] == 1:
                q1(0, 0, max_range, i, i, 1)
        for x, y, z in queries:
            if x == 3:
                ans.append(self.sum)
            if x == 2:
                self.sum += p_1[0] * y
            if x == 1:
                q1(0, 0, max_range, y, z, 1)
        return ans
            




data = Solution()
nums1 = [1,0,1]
nums2 = [0,0,0]
queries = [[1,1,1],[2,1,0],[3,0,0]]
print(data.handleQuery(nums1, nums2, queries))
nums1 = [1,0,1]
nums2 = [0,0,0]
queries = [[1,0,1],[3,0,0],[3,0,0],[1,2,2],[1,1,2],[2,1,0],[3,0,0]]
print(data.handleQuery(nums1, nums2, queries))
